/**
 * @Author: 颜兴旺
 * @Date: 2019/8/31
 * @Last Modified by:   颜兴旺
 * @Last Modified time: 2019-06-20 15:45:00
 */
import _ from 'lodash';
import * as types from '../types';

// state  费用结算页面，数据传值
const state = {
  taxRate: 0,
  receivableSelectInfo: [], // 应收整单拆分列表数据
  netReceiptsInfoList: [], // 实收列表数据
  newSplitObjectList: [], // 新拆分对象列表
  zeroEliminationData: 0, // 去零金额
  // 存储费用结算页面所有列表数据
  maintenanceSyncTable: [], //维修项目的列表数据
  maintenanceMaterialsSyncTable: [], // 维修材料的列表数据
  salesMaterialsSyncTable: [], // 销售材料的列表数据
  additionalItemsSyncTable: [], // 附加项目的列表数据
  netReceiptsSyncTable: [], //实收tab中的列表数据
  receivableSyncTable: [] //应收tab中的列表数据
};

// actions
const actions = {
  createreceivableSelectInfo({ commit, state }, params) {
    commit({
      type: types.RECEIVABLE_SELECT_INFO_YXW,
      data: params
    });
  },
  createTaxRate({ commit, state }, params) {
    commit({
      type: types.TAX_RATE_YXW,
      data: params
    });
  },
  createNewSplitObjectList({ commit, state }, params) {
    commit({
      type: types.NEW_SPLIT_OBJECT_LIST_YXW,
      data: params
    });
  },
  createZeroEliminationData({ commit, state }, params) {
    commit({
      type: types.ZERO_ELIMINATION_DATA_YXW,
      data: params
    });
  },
  createMaintenanceSyncTable({ commit, state }, params) {
    commit({
      type: types.MAINTENANCE_SYNC_TABLE_YXW,
      data: params
    });
  },
  createMaintenanceMaterialsSyncTable({ commit, state }, params) {
    commit({
      type: types.MAINTENANCE_MATERIALS_SYNC_TABLE_YXW,
      data: params
    });
  },
  createSalesMaterialsSyncTable({ commit, state }, params) {
    commit({
      type: types.SALESMATERIALS_SYNC_TABLE_YXW,
      data: params
    });
  },
  createAdditionalItemsSyncTable({ commit, state }, params) {
    commit({
      type: types.ADDITIONAL_ITEMS_SYNC_TABLE_YXW,
      data: params
    });
  },
  createNetReceiptsSyncTable({ commit, state }, params) {
    commit({
      type: types.NET_RECEIPTS_SYNC_TABLE_YXW,
      data: params
    });
  },
  createReceivableSyncTable({ commit, state }, params) {
    commit({
      type: types.RECEIVABLE_SYNC_TABLE_YXW,
      data: params
    });
  }
};

// mutations
const mutations = {
  [types.RECEIVABLE_SELECT_INFO_YXW](state, { data }) {
    state.receivableSelectInfo = data;
  },
  [types.TAX_RATE_YXW](state, { data }) {
    state.taxRate = data;
  },
  [types.NEW_SPLIT_OBJECT_LIST_YXW](state, { data }) {
    state.newSplitObjectList = data;
  },
  [types.ZERO_ELIMINATION_DATA_YXW](state, { data }) {
    state.zeroEliminationData = data;
  },
  [types.MAINTENANCE_SYNC_TABLE_YXW](state, { data }) {
    state.maintenanceSyncTable = data;
  },
  [types.MAINTENANCE_MATERIALS_SYNC_TABLE_YXW](state, { data }) {
    state.maintenanceMaterialsSyncTable = data;
  },
  [types.SALESMATERIALS_SYNC_TABLE_YXW](state, { data }) {
    state.salesMaterialsSyncTable = data;
  },
  [types.ADDITIONAL_ITEMS_SYNC_TABLE_YXW](state, { data }) {
    state.additionalItemsSyncTable = data;
  },
  [types.NET_RECEIPTS_SYNC_TABLE_YXW](state, { data }) {
    state.netReceiptsSyncTable = data;
  },
  [types.RECEIVABLE_SYNC_TABLE_YXW](state, { data }) {
    state.receivableSyncTable = data;
  }
};

// getters
const getters = {
  newSplitObjectList_get: state => state.newSplitObjectList,
  zeroEliminationData_get: state => state.zeroEliminationData
};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
};
